package com.googlecode.tda367.denty.core.level;



import java.util.ArrayList;
import java.util.List;

import org.jbox2d.dynamics.World;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

import com.googlecode.tda367.denty.core.camera.Camera;
import com.googlecode.tda367.denty.core.camera.MovingCamera;
import com.googlecode.tda367.denty.core.dynamicbody.Block;
import com.googlecode.tda367.denty.core.dynamicbody.BouncingEnemy;
import com.googlecode.tda367.denty.core.dynamicbody.DynamicBody;
import com.googlecode.tda367.denty.core.dynamicbody.SimpleEnemy;

public class TutorialLevel extends AbstractLevel {
	
	// Keeps track of the viewport
	private Camera camera;
	private TiledMap map;
	
	public TutorialLevel() {
		try {
			this.map = new TiledMap(this.getTiledMapPath());
		} catch (SlickException e) {
			e.printStackTrace();
		}
		this.parseTiledMap(this.map);
		
		this.addBodies();
		
		this.camera = new MovingCamera(this.getWidth(), this.getHeight());
	}
	
	private void addBodies() {
		List<DynamicBody> bodies = new ArrayList<DynamicBody>();
		World world = this.getWorld();
		
		//Enemies
		SimpleEnemy enemy = new SimpleEnemy(50f, 22f, world);
		enemy.setXBounds(16f, 51f);
		bodies.add(enemy);
		bodies.add(new BouncingEnemy(15f, 35, world));
		
		//Blocks
		bodies.add(new Block(world, 14, 17));
		bodies.add(new Block(world, 15, 17));
		bodies.add(new Block(world, 16, 17));
		bodies.add(new Block(world, 17, 17));
		bodies.add(new Block(world, 83, 49));
		bodies.add(new Block(world, 84, 49));
		
		// Throwable blocks
		this.newThrowableBlock(3, 13);
		this.newThrowableBlock(4, 13);
		this.newThrowableBlock(3.5f, 12);
		this.addDynamicBodies(bodies);
		
	}

	@Override
	public int getWidth() {
		return this.map.getWidth();
	}
	
	@Override
	public int getHeight() {
		return this.map.getHeight();
	}
	
	@Override
	public Camera getCamera(){
		return this.camera;
	}

	@Override
	public String getTiledMapPath() {
		return "res/lvl/tutorial-level.tmx";
	}


	@Override
	public int getDentyStartX() {
		return 12;
	}


	@Override
	public int getDentyStartY() {
		return 15;
	}


	@Override
	public int getGoalX() {
		return 95;
	}


	@Override
	public int getGoalY() {
		return 46;
	}


	@Override
	public int getMaxAvailableBlocks() {
		return 10;
	}


	@Override
	public int getBlocksAvailableFromStart() {
		return 2;
	}
}